<template>
  <div style="min-width:1366px;">
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable @clear="clearEvent"></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <!-- 主页列表 -->
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="tableData"
          border
          ref="table"
          :height="tableHeight"
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          style="width: 100%;font-size:12px"
        >
          <el-table-column type="index" label="序列号" width="60"></el-table-column>
          <el-table-column label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.pediatricDrugId>0"
                @click="showChildrenRule(scope.row.pediatricDrugId)"
                type="text"
              >查看</el-button>
              <el-button type="text" @click="showAddRule(scope.row.drugCode)">新增</el-button>
            </template>
          </el-table-column>

          <el-table-column prop="drugName" label="药品名称"></el-table-column>
          <el-table-column prop="nameType" label="药品类型">
            <template
              slot-scope="scope"
            >{{(scope.row.nameType==8)?"西药":(scope.row.nameType==2)?"草药":"中成药"}}</template>
          </el-table-column>
          <el-table-column prop="formName" label="剂型名称"></el-table-column>
          <el-table-column prop="drugSpec" label="药品规格"></el-table-column>
          <el-table-column prop="compName" label="药品生产厂家"></el-table-column>
          <el-table-column prop="approvalCode" label="批准文号"></el-table-column>
          <el-table-column prop="doseUnit" label="给药单位"></el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <!-- 添加儿童审查规 -->
    <el-dialog
      title="添加儿童审查规"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <div class="addRuleAdverse">
        <el-form
          :inline="true"
          :model="addRuleData"
          class="demo-form-inline addForm"
          label-width="150px"
          :rules="Formrules"
          ref="addRuleData"
        >
          <el-form-item label="给药类型" prop="routeType">
            <el-select v-model="addRuleData.routeType" size="medium" placeholder="请选择">
              <el-option
                v-for="item in RouteOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="给药途径ID" prop="routeName">
            <el-input v-model="addRuleData.routeName" size="medium">
              <el-button slot="append" @click="showRoute(1)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="疾病编码" prop="zdmc">
            <el-input v-model="addRuleData.zdmc" size="medium">
              <el-button slot="append" @click="showIcdCode(1)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="年龄低值" prop="ageLow">
            <el-input v-model.number="addRuleData.ageLow" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="是否不等于年龄低值" prop="unequalLow">
            <el-select v-model="addRuleData.unequalLow" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年龄低值单位" prop="ageLowUnit">
            <el-select v-model="addRuleData.ageLowUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="年龄高值" prop="ageHigh">
            <el-input v-model.number="addRuleData.ageHigh" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="是否不等于年龄高值" prop="unequalHigh">
            <el-select v-model="addRuleData.unequalHigh" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年龄高值单位" prop="ageHighUnit">
            <el-select v-model="addRuleData.ageHighUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="警示级别" prop="slCode">
            <el-select v-model="addRuleData.slCode" size="medium" placeholder="请选择">
              <el-option
                v-for="item in SlOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="警示信息" prop="warning">
            <el-input type="textarea" :rows="5" v-model="addRuleData.warning" size="medium"></el-input>
          </el-form-item>
          <!-- 
          <el-form-item label="给药途径描述">
            <el-input v-model="addRuleData.routeName" size="medium">
              <el-button slot="append">选择</el-button>
            </el-input>
          </el-form-item>-->
          <!-- <el-form-item label="警示级别">
            <el-select
              v-model="addRuleData.slcode"
              size="medium"
              placeholder="请选择"
            >
              <el-option
                v-for="item in SlOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>-->
          <el-form-item label="问题详细信息描述" prop="abstractDesc">
            <el-input type="textarea" :rows="5" v-model="addRuleData.abstractDesc" size="medium"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addRule()">新 增</el-button>
        <el-button @click="cancel('addRuleData');dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 选择给药途径ID -->
    <el-dialog
      title="选择给药途径"
      :visible.sync="RouteVisible"
      class="editDialog"
      width="30%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:527px">
        <div class="addInput">
          <el-input v-model="routeData.srm" size="small" placeholder="请输入内容"></el-input>
          <el-button style="margin-right:8px" type="primary" size="small" @click="SearchDrug()">搜索</el-button>
        </div>
        <el-table
          :data="routeData.tableData"
          stripe
          border
          height="400"
          style="width: 100%;font-size: 10px"
          :header-cell-style="{'text-align':'center'}"
          :row-style="{height:'40px'}"
          :cell-style="{'text-align':'center',padding:'0px'}"
          @row-click="handleRow1"
          @selection-change="handleSelectionChange1"
        >
          <el-table-column label width="35">
            <template slot-scope="scope">
              <el-radio
                :label="scope.row"
                v-model="routeData.radioId"
                @change.native="handleSelectionChange1(scope.row)"
              >&nbsp;</el-radio>
            </template>
          </el-table-column>

          <el-table-column prop="routeId" width="150" label="给药途径编码"></el-table-column>
          <el-table-column prop="routeName" label="给药途径名称"></el-table-column>
        </el-table>
        <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
        <div class="dialogBlock">
          <el-pagination
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"
            current-page.sync="1"
            :page-size="100"
            layout="total, prev, pager, next"
            :total="routeData.total"
          ></el-pagination>
        </div>
        <span slot="footer" class="dialog-footer">
          <div class="SortFoot">
            <el-button
              style="margin-right:8px"
              type="primary"
              size="small"
              @click="SelectRoute(1)"
            >确定</el-button>
            <el-button style="margin-right:8px" @click="RouteVisible = false" size="small">取消</el-button>
          </div>
        </span>
      </div>
    </el-dialog>
    <!-- 选择选择给药途径 -->
    <el-dialog
      title="选择疾病"
      :visible.sync="IcdCodeVisible"
      class="editDialog"
      width="30%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:527px">
        <div class="addInput">
          <el-input v-model="IcdCodeData.srm" size="small" placeholder="请输入内容"></el-input>
          <el-button
            style="margin-right:8px"
            type="primary"
            size="small"
            @click="SearchIcdCodeData()"
          >搜索</el-button>
        </div>
        <el-table
          :data="IcdCodeData.tableData"
          stripe
          border
          height="400"
          style="width: 100%;font-size: 10px"
          :header-cell-style="{'text-align':'center'}"
          :row-style="{height:'40px'}"
          :cell-style="{'text-align':'center',padding:'0px'}"
          @row-click="handleRow"
          @selection-change="handleSelectionChange"
        >
          <el-table-column label width="35">
            <template slot-scope="scope">
              <el-radio :label="scope.row" v-model="IcdCodeData.radioId">&nbsp;</el-radio>
            </template>
          </el-table-column>

          <el-table-column prop="zddm" width="150" label="诊断代码"></el-table-column>
          <el-table-column prop="zdmc" label="诊断名称"></el-table-column>
        </el-table>
        <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
        <div class="dialogBlock">
          <el-pagination
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
            current-page.sync="1"
            :page-size="queryInfo.pageSize"
            layout="total, prev, pager, next"
            :total="IcdCodeData.total"
          ></el-pagination>
        </div>
        <span slot="footer" class="dialog-footer">
          <div class="SortFoot">
            <el-button
              style="margin-right:8px"
              type="primary"
              size="small"
              @click="SelectIcdCode()"
            >确定</el-button>
            <el-button style="margin-right:8px" @click="IcdCodeVisible = false" size="small">取消</el-button>
          </div>
        </span>
      </div>
    </el-dialog>
    <!-- 所有儿童用药审查 -->
    <el-dialog
      title="所有儿童用药审查"
      :visible.sync="ChildrenRuleAllVisible"
      class="editDialog"
      width="55%"
      stripe
      :before-close="handleClose"
    >
      <div>
        <el-card style="height:530px">
          <el-table
            :data="ChildrenRuleData.ChildrenRuleTableData"
            :header-cell-style="{'text-align':'center'}"
            :cell-style="{'text-align':'center',padding:'0px'}"
            border
            stripe
            height="450"
            style="width: 100%"
          >
            <el-table-column type="index" label="序号" width="50" fixed></el-table-column>
            <el-table-column label="操作" width="100" fixed>
              <template slot-scope="scope">
                <el-button
                  type="text"
                  style="margin-right:12px"
                  @click="showChildrenRuleOne(scope.row.id)"
                >查看</el-button>
                <el-button type="text" @click="open(scope.row.id,scope.row.drugId)">删除</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="routeType" label="给药类型" width="100">
              <template
                slot-scope="scope"
              >{{(scope.row.routeType==1)?"全身给药":(scope.row.routeType==2)?"局部给药":(scope.row.routeType==3)?"所有方式给药":(scope.row.routeType==0)?"系统默认":""}}</template>
            </el-table-column>
            <el-table-column prop="routeIds" label="给药途径" width="100"></el-table-column>
            <el-table-column prop="ageLow" label="年龄低值" width="100"></el-table-column>
            <el-table-column prop="unequalLow" label="是否不等于年龄低值" width="170">
              <!-- 0-等于 1-不等于 -->
              <template
                slot-scope="scope"
              >{{(scope.row.unequalLow==0)?"等于":(scope.row.unequalLow==1)?"不等于":""}}</template>
            </el-table-column>
            <el-table-column prop="ageLowUnit" label="年龄低值单位" width="150"></el-table-column>
            <el-table-column prop="ageHigh" label="年龄高值" width="100"></el-table-column>
            <el-table-column prop="unequalHigh" label="是否不等于年龄高值" width="170">
              <!-- 0-等于 1-不等于 -->
              <template
                slot-scope="scope"
              >{{(scope.row.unequalLow==0)?"等于":(scope.row.unequalLow==1)?"不等于":""}}</template>
            </el-table-column>
            <el-table-column prop="ageHighUnit" label="年龄高值单位" width="150"></el-table-column>
            <el-table-column prop="icdCodes" label="疾病编码" width="100"></el-table-column>
            <el-table-column prop="slCode" label="警示级别" width="100">
              <template slot-scope="scope">
                <!-- 0:拦截，1：禁忌，2：不推荐，3：轻微 -->
                {{(scope.row.slCode==0)?"拦截":(scope.row.slCode==1)?"禁忌":(scope.row.slCode==2)?"不推荐":(scope.row.slCode==3)?"轻微":""}}
              </template>
            </el-table-column>
            <el-table-column prop="warning" label="警告内容" width="100"></el-table-column>
            <el-table-column prop="abstractDesc" label="问题详细信息描述" width="170"></el-table-column>
          </el-table>
          <el-pagination
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
            :current-page="1"
            :page-sizes="[20, 30, 50]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="ChildrenRuleData.total"
          ></el-pagination>
        </el-card>
      </div>
    </el-dialog>
    <!-- 查看一条规则 -->
    <el-dialog
      title="查看规则"
      :visible.sync="ChildrenRuleOneVisible"
      width="50%"
      :before-close="handleClose"
    >
      <div class="addRuleAdverse">
        <el-form
          :inline="true"
          :model="ChildrenRuleOneData"
          class="demo-form-inline addForm"
          label-width="150px"
        >
          <el-form-item label="给药类型">
            <el-select v-model="ChildrenRuleOneData.routeType" size="medium" placeholder="请选择">
              <el-option
                v-for="item in RouteOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="给药途径">
            <el-input v-model="ChildrenRuleOneData.routeName" size="medium">
              <el-button slot="append" @click="showRoute(2)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="疾病编码">
            <el-input v-model="ChildrenRuleOneData.icdName" size="medium">
              <el-button slot="append" @click="showIcdCode(2)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="年龄低值">
            <el-input v-model="ChildrenRuleOneData.ageLow" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="是否不等于年龄低值">
            <el-select v-model="ChildrenRuleOneData.unequalLow" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年龄低值单位">
            <el-select v-model="ChildrenRuleOneData.ageLowUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="年龄高值">
            <el-input v-model="ChildrenRuleOneData.ageHigh" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="是否不等于年龄高值">
            <el-select v-model="ChildrenRuleOneData.unequalHigh" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年龄高值单位">
            <el-select v-model="ChildrenRuleOneData.ageHighUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="警示级别">
            <el-select v-model="ChildrenRuleOneData.slCode" size="medium" placeholder="请选择">
              <el-option
                v-for="item in SlOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="警示信息">
            <el-input type="textarea" :rows="3" v-model="ChildrenRuleOneData.warning" size="medium"></el-input>
          </el-form-item>
          <!-- 
          <el-form-item label="给药途径描述">
            <el-input v-model="addRuleData.routeName" size="medium">
              <el-button slot="append">选择</el-button>
            </el-input>
          </el-form-item>-->
          <!-- <el-form-item label="警示级别">
            <el-select
              v-model="ChildrenRuleOneData.slCode"
              size="medium"
              placeholder="请选择"
            >
              <el-option
                v-for="item in SlOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>-->
          <el-form-item label="问题详细信息描述">
            <el-input
              type="textarea"
              :rows="3"
              v-model="ChildrenRuleOneData.abstractDesc"
              size="medium"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="UpdateRuleone()">更 新</el-button>
        <el-button @click="ChildrenRuleOneVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getChildrenList,
  getRouteJson,
  getIcdCodeJson,
  addChildrenRule,
  getChildrenRuleOne,
  UpdateRuleone,
  deleteRule,
} from "@/api/rad";
export default {
  data() {
    var checkAgeLow = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("年龄不能为空"));
      }

      if (!Number.isInteger(value)) {
        callback(new Error("请输入数字值"));
      } else {
        if (value < 0) {
          callback(new Error("年龄必须大于0"));
        } else {
          callback();
        }
      }
    };
    var checkAgeHigh = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("年龄不能为空"));
      }
      if (!Number.isInteger(value)) {
        callback(new Error("请输入数字值"));
      } else {
        if (value < 0) {
          callback(new Error("年龄必须大于0"));
        } else {
          callback();
        }
      }
    };
    // var checkrouteType = (rule, value, callback) => {
    //   if (!value) {
    //     return callback(new Error("给药类型不能为空"));
    //   }
    // };
    // var checkrouteName = (rule, value, callback) => {
    //   if (!value) {
    //     return callback(new Error("给药途径不能为空"));
    //   }
    // };
    // var checkzdmc = (rule, value, callback) => {
    //   if (!value) {
    //     return callback(new Error("疾病编码不能为空"));
    //   }
    // };
    // var checkunequalLow = (rule, value, callback) => {
    //   if (!value) {
    //     return callback(new Error("年龄低值不能为空"));
    //   }
    // };
    return {
      tableHeight: 250,
      multipleSelection: {},
      queryInfo: {
        srm: "",
        pageList: 1,
        pageSize: 20,
      },
      total: 0,
      tableData: [],
      dialogVisible: false,
      addRuleData: {
        routeType: "",
        routeIds: "",
        // 配对途径ID
        routeName: "",
        ageLow: "",
        unequalLow: "",
        ageLowUnit: "",
        ageHigh: "",
        unequalHigh: "",
        ageHighUnit: "",
        icdCodes: "",
        zdmc: "",
        slCode: "",
        warning: "",
        abstractDesc: "",
        drugCode: "",
      },
      // routeType 给药类型 1  全身给药     2  局部给药  3  所有方式给药   0  系统默认
      RouteOptions: [
        {
          value: 1,
          label: "全身给药",
        },
        {
          value: 2,
          label: "局部给药",
        },
        {
          value: 3,
          label: "所有方式给药",
        },
        {
          value: 0,
          label: "系统默认",
        },
      ],
      LowOptions: [
        {
          value: 0,
          label: "等于",
        },
        {
          value: 1,
          label: "不等于",
        },
      ],
      LowUnitOptions: [
        {
          value: "周",
          label: "周",
        },
        {
          value: "月",
          label: "月",
        },
        {
          value: "岁",
          label: "岁",
        },
      ],
      SlOptions: [
        {
          value: 0,
          label: "拦截",
        },
        {
          value: 1,
          label: "禁忌",
        },
        {
          value: 2,
          label: "不推荐",
        },
        {
          value: 3,
          label: "轻微",
        },
      ],
      RouteVisible: false,
      routeData: {
        srm: "",
        page: "",
        pageSize: "",
        load: 0,
        total: 0,
        tableData: [],
        radioId: [],
      },
      IcdCodeVisible: false,
      IcdCodeData: {
        load: 0,
        srm: "",
        page: 1,
        pageSize: 20,
        total: 0,
        tableData: [],
        radioId: [],
      },
      ChildrenRuleAllVisible: false,
      ChildrenRuleData: {
        pediatricDrugId: "",
        total: 0,
        ChildrenRuleTableData: [],
      },
      ChildrenRuleOneVisible: false,
      ChildrenRuleOneData: {
        id: "",
        routeType: "",
        routeIds: "",
        routeName: "",
        ageLow: "",
        unequalLow: "",
        ageLowUnit: "",
        ageHigh: "",
        unequalHigh: "",
        ageHighUnit: "",
        icdCodes: "",
        icdName: "",
        slCode: "",
        warning: "",
        abstractDesc: "",
      },
      Formrules: {
        ageLow: [{ validator: checkAgeLow, trigger: "blur" }],
        ageHigh: [{ validator: checkAgeHigh, trigger: "blur" }],
        // routeType: [{ validator: checkrouteType, trigger: "blur" }],
        // routeName: [{ validator: checkrouteName, trigger: "blur" }],
        // zdmc: [{ validator: checkzdmc, trigger: "blur" }],

        // unequalLow: [{ validator: checkunequalLow, trigger: "blur" }],
        // unequalHigh: [{ validator: checkunequalHigh, trigger: "blur" }],
        // ageLowUnit: [{ validator: checkageLowUnit, trigger: "blur" }],
        // // 年龄低值单位
        // ageHighUnit: [{ validator: checkageHighUnit, trigger: "blur" }],
        // slCode: [{ validator: checkslCode, trigger: "blur" }],
        // warning: [{ validator: checkwarning, trigger: "blur" }],
        // abstractDesc: [{ validator: checkabstractDesc, trigger: "blur" }]
      },
    };
  },
  mounted: function () {
    this.$nextTick(function () {
      this.tableHeight =
        window.innerHeight - this.$refs.table.$el.offsetTop - 50;
      // 监听窗口大小变化
      let self = this;
      window.onresize = function () {
        self.tableHeight =
          window.innerHeight - self.$refs.table.$el.offsetTop - 50;
      };
    });
  },
  created: function () {
    this.getChildrenList();
  },
  methods: {
    handleClose(done) {
      done();
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getChildrenList();
    },

    handleCurrentChange(newPage) {
      this.queryInfo.pageList = newPage;
      this.getChildrenList();
    },
    handleSizeChange1(newSize) {
      this.routeData.pageSize = newSize;
      this.getRouteJson();
    },

    handleCurrentChange1(newPage) {
      this.routeData.page = newPage;
      this.getRouteJson();
    },
    handleSizeChange2(newSize) {
      this.IcdCodeData.pageSize = newSize;
      this.getIcdCodeJson();
    },

    handleCurrentChange2(newPage) {
      this.IcdCodeData.page = newPage;
      this.getIcdCodeJson();
    },
    async getChildrenList() {
      let res = await this.$rad.getChildrenList({
        srm: this.queryInfo.srm,
        page: this.queryInfo.pageList,
        pageSize: this.queryInfo.pageSize,
      });
      (this.tableData = res.rows), (this.total = res.total);
      console.log(res.rows);
    },
    getSearchList() {
      this.getChildrenList();
    },
    showAddRule(drugCode) {
      this.addRuleData.drugCode = drugCode;
      this.dialogVisible = true;
    },
    clearEvent() {},
    showRoute(load) {
      this.RouteVisible = true;
      this.routeData.load = load;
      this.getRouteJson();
    },
    showIcdCode(load) {
      this.IcdCodeData.load = load;
      this.IcdCodeVisible = true;
      this.getIcdCodeJson();
    },
    async getRouteJson() {
      let res = await this.$rad.getRouteJson({
        srm: this.routeData.srm,
        page: this.routeData.page,
        pageSize: this.routeData.pageSize,
      });
      console.log(res);
      this.routeData.tableData = res.rows;
      this.routeData.total = res.total;
    },
    async getIcdCodeJson() {
      let res = await this.$rad.getIcdCodeJson({
        srm: this.IcdCodeData.srm,
        page: this.IcdCodeData.page,
        pageSize: this.IcdCodeData.pageSize,
      });
      console.log(res);
      this.IcdCodeData.tableData = res.rows;
      this.IcdCodeData.total = res.total;
    },
    SelectRoute() {
      if (this.routeData.radioId.length == 0) {
        return this.$message({
          type: "warning",
          message: "未选择给药途径",
        });
      } else {
        if (this.routeData.load == 1) {
          this.addRuleData.routeName = this.routeData.radioId.routeName;
          this.addRuleData.routeIds = this.routeData.radioId.routeId;
        } else if (this.routeData.load == 2) {
          console.log(this.routeData.radioId);
          this.ChildrenRuleOneData.routeName = this.routeData.radioId.routeName;
          this.ChildrenRuleOneData.routeIds = this.routeData.radioId.routeId;
        }
        this.RouteVisible = false;
      }
    },
    SelectIcdCode() {
      if (this.IcdCodeData.radioId.length == 0) {
        return this.$message({
          type: "warning",
          message: "未选择疾病",
        });
      } else {
        if (this.IcdCodeData.load == 1) {
          this.addRuleData.icdCodes = this.IcdCodeData.radioId.zddm;
          this.addRuleData.zdmc = this.IcdCodeData.radioId.zdmc;
        } else if (this.IcdCodeData.load == 2) {
          this.ChildrenRuleOneData.icdCodes = this.IcdCodeData.radioId.zddm;
          this.ChildrenRuleOneData.icdName = this.IcdCodeData.radioId.zdmc;
        }

        this.IcdCodeVisible = false;
      }
    },
    SearchIcdCodeData() {
      this.getIcdCodeJson();
    },
    async addRule() {
      console.log(this.addRuleData);
      if (this.addRuleData.routeType === "") {
        this.$message({
          type: "warning",
          message: "请填写给药类型",
        });
      } else if (this.addRuleData.routeIds === "") {
        this.$message({
          type: "warning",
          message: "请选择给药途径ID",
        });
      } else if (this.addRuleData.ageLow === "") {
        this.$message({
          type: "warning",
          message: "请填写年龄低值",
        });
      } else if (this.addRuleData.unequalLow === "") {
        this.$message({
          type: "warning",
          message: "请选择给药年龄低值参数",
        });
      } else if (this.addRuleData.ageLowUnit === "") {
        this.$message({
          type: "warning",
          message: "请选择年龄低值单位",
        });
      } else if (this.addRuleData.ageHigh === "") {
        this.$message({
          type: "warning",
          message: "请填写年龄高值",
        });
      } else if (this.addRuleData.unequalHigh === "") {
        this.$message({
          type: "warning",
          message: "请选择给药年龄高值参数",
        });
      } else if (this.addRuleData.ageHighUnit === "") {
        this.$message({
          type: "warning",
          message: "请选择年龄高值单位",
        });
      } else if (this.addRuleData.icdCodes === "") {
        this.$message({
          type: "warning",
          message: "请选择疾病编码",
        });
      } else if (this.addRuleData.slCode === "") {
        this.$message({
          type: "warning",
          message: "请选择警示级别",
        });
      } else if (this.addRuleData.warning === "") {
        this.$message({
          type: "warning",
          message: "请填写警示信息",
        });
      } else if (this.addRuleData.abstractDesc === "") {
        this.$message({
          type: "warning",
          message: "请填写问题详细信息描述",
        });
      } else {
        let res = await this.$rad.addChildrenRule({
          routeType: this.addRuleData.routeType,
          routeIds: this.addRuleData.routeIds,
          ageLow: this.addRuleData.ageLow,
          unequalLow: this.addRuleData.unequalLow,
          ageLowUnit: this.addRuleData.ageLowUnit,
          ageHigh: this.addRuleData.ageHigh,
          unequalHigh: this.addRuleData.unequalHigh,
          ageHighUnit: this.addRuleData.ageHighUnit,
          icdCodes: this.addRuleData.icdCodes,
          slCode: this.addRuleData.slCode,
          warning: this.addRuleData.warning,
          abstractDesc: this.addRuleData.abstractDesc,
          drugCode: this.addRuleData.drugCode,
        });
        if (res.code == 1) {
          this.dialogVisible = false;
          this.clearaddRuleData();
          this.getChildrenList();
          return this.$message({
            type: "success",
            message: res.msg,
          });
        } else {
          return this.$message({
            type: "error",
            message: res.msg,
          });
        }
      }
    },
    clearaddRuleData() {
      (this.addRuleData.routeType = ""),
        (this.addRuleData.routeIds = ""),
        (this.addRuleData.routeName = ""),
        (this.addRuleData.ageLow = ""),
        (this.addRuleData.unequalLow = ""),
        (this.addRuleData.ageLowUnit = ""),
        (this.addRuleData.ageHigh = ""),
        (this.addRuleData.unequalHigh = ""),
        (this.addRuleData.ageHighUnit = ""),
        (this.addRuleData.icdCodes = ""),
        (this.addRuleData.zdmc = ""),
        (this.addRuleData.slCode = ""),
        (this.addRuleData.warning = ""),
        (this.addRuleData.abstractDesc = ""),
        (this.addRuleData.drugCode = "");
    },
    showChildrenRule(pediatricDrugId) {
      this.ChildrenRuleAllVisible = true;
      this.ChildrenRuleData.pediatricDrugId = pediatricDrugId;
      this.getChildrenRuleAll();
    },
    async getChildrenRuleAll() {
      let res = await this.$rad.getChildrenRuleAll({
        drugId: this.ChildrenRuleData.pediatricDrugId,
        page: 1,
        pageSize: 50,
      });
      console.log(res);
      this.ChildrenRuleData.total = res.total;
      this.ChildrenRuleData.ChildrenRuleTableData = res.rows;
    },
    showChildrenRuleOne(id) {
      this.ChildrenRuleOneVisible = true;
      this.ChildrenRuleOneData.id = id;
      this.getChildrenRuleOne();
    },
    async getChildrenRuleOne() {
      let res = await this.$rad.getChildrenRuleOne({
        id: this.ChildrenRuleOneData.id,
      });
      console.log(res);
      (this.ChildrenRuleOneData.routeType = res.data.routeType),
        (this.ChildrenRuleOneData.routeName = res.data.routeIds),
        (this.ChildrenRuleOneData.ageLow = res.data.ageLow),
        (this.ChildrenRuleOneData.unequalLow = res.data.unequalLow),
        (this.ChildrenRuleOneData.ageLowUnit = res.data.ageLowUnit),
        (this.ChildrenRuleOneData.ageHigh = res.data.ageHigh),
        (this.ChildrenRuleOneData.unequalHigh = res.data.unequalHigh),
        (this.ChildrenRuleOneData.ageHighUnit = res.data.ageHighUnit),
        (this.ChildrenRuleOneData.icdName = res.data.icdCodes),
        (this.ChildrenRuleOneData.slCode = res.data.slCode),
        (this.ChildrenRuleOneData.warning = res.data.warning),
        (this.ChildrenRuleOneData.abstractDesc = res.data.abstractDesc);
    },
    async UpdateRuleone() {
      let res = await this.$rad.UpdateRuleone({
        id: this.ChildrenRuleOneData.id,
        routeType: this.ChildrenRuleOneData.routeType,
        routeIds: this.ChildrenRuleOneData.routeIds,
        ageLow: this.ChildrenRuleOneData.ageLow,
        unequalLow: this.ChildrenRuleOneData.unequalLow,
        ageLowUnit: this.ChildrenRuleOneData.ageLowUnit,
        ageHigh: this.ChildrenRuleOneData.ageHigh,
        unequalHigh: this.ChildrenRuleOneData.unequalHigh,
        ageHighUnit: this.ChildrenRuleOneData.ageHighUnit,
        icdCodes: this.ChildrenRuleOneData.icdCodes,
        slCode: this.ChildrenRuleOneData.slCode,
        warning: this.ChildrenRuleOneData.warning,
        abstractDesc: this.ChildrenRuleOneData.abstractDesc,
      });
      console.log(res);
      if (res.code == 1) {
        this.ChildrenRuleOneVisible = false;
        this.getChildrenRuleAll();
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$message({
          type: "error",
          message: res.msg,
        });
      }
    },
    open(id, drugId) {
      this.$confirm("此操作将永久删除该规则, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.deleteRule(id, drugId);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    async deleteRule(id, drugId) {
      let res = await this.$rad.deleteRule({
        id: id,
        drugId: drugId,
      });
      console.log(res);
      if (res.code == 1) {
        this.getChildrenList();
        this.getChildrenRuleAll();
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$message({
          type: "success",
          message: res.msg,
        });
      }
    },
    cancel(formName) {
      this.$refs[formName].clearValidate();
    },
    handleRow(row) {
      console.log(row);
      this.IcdCodeData.radioId = row;
      this.multipleSelection = row;
    },
    handleSelectionChange(val) {
      console.log(res);
      this.multipleSelection = val;
    },
    handleRow1(row) {
      console.log(row);
      this.routeData.radioId = row;
      this.multipleSelection = row;
    },
    handleSelectionChange1(val) {
      console.log(res);
      this.multipleSelection = val;
    },
  },
};
</script>
<style  scoped>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
.editDialog >>> .el-dialog__header {
  margin-bottom: 0px;
}
.editDialog >>> .el-dialog__body {
  padding-left: 0px;
  padding-right: 0px;
}
.addInput {
  height: 45px;
  display: flex;
  align-items: center;
}
.SortFoot {
  height: 50px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.addInput >>> .el-input {
  width: 40%;
  margin-left: 8px;
}
.addInput >>> .el-button {
  margin-left: 8px;
}
.dialogBlock {
  margin-top: 0px;
  margin-bottom: 0px;
}
.addForm >>> .el-form-item__content {
  width: 200px;
}
</style>